import axios  from "axios";
import router from "@/router";
import { ElMessage } from 'element-plus';

const HTTP = axios.create({
    timeout: 3000
})

HTTP.interceptors.response.use(resolve => {
    console.log(resolve);
    if(resolve.data.msg === "NOTLOGIN" && resolve.data.code == 0){
        ElMessage.error('当前系统未登录，三秒后自动跳转登录页面');
        router.push('/login');
    }else{
        return resolve.data;
    }
},error => {
    console.log(error);
    let { message } = error;
    if(message.includes('Request failed with status code')){
        ElMessage.error('服务器未响应');
    };


})

export default HTTP ;